<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2016/12/21
 * Time: 9:23
 */

namespace YMApi\Model;


use Think\Model;

/**
 * Class HomeTemplateModel
 * @package SDXApi\Model
 */
class HomeTemplateModel extends Model
{

	/**
	 * @var string
	 */
	protected $tableName = 'home_template';


	/**
	 * Created by Jerry
	 * @param $id
	 * @return mixed
	 */
	public function find_home_template_for_status_by_id($id)
	{
		$time = time();

		$where = array(
//			'id'	=>	$id,
			'status'=>	1,
			'start_time'=>	array('LT', $time,),
			'end_time'	=>	array('GT', $time,),
		);

		return $this->where($where)->find();
	}

	/**
	 * 获取分组信息
	 * Created by Jerry
	 * @param $groupId
	 * @param int $isShow
	 * @return mixed
	 */
	public function find_home_template_by_group_id($groupId, $isShow = 1)
	{
		$where = array(
			'id'	=>	$groupId,
			'status'=>	1,
		);

		if ($isShow == 0) {
			unset($where['status']);
		}

		return $this->where($where)->find();
	}

	/**
	 * 返回该分组下当前启用的模块
	 * Created by Jerry
	 * @param $parentId
	 * @param int $isShow
	 * @return mixed
	 */
	public function find_home_template_by_parent_id($parentId, $isShow = 1)
	{
		$time = time();

		$where = array(
			'parent_id'	=>	$parentId,
			'status'	=>	1,
			'start_time'=>	array('LT', $time,),
			'end_time'	=>	array('GT', $time,),
		);

		if ($isShow == 0) {
			unset($where['status']);
		}

		return $this->where($where)->find();
	}

}